﻿namespace System.Workflow.ComponentModel
{
    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Drawing;
    using System.Workflow.ComponentModel.Compiler;
    using System.Workflow.ComponentModel.Design;

    [Designer(typeof(SuspendDesigner), typeof(IDesigner)), SRDescription("SuspendActivityDescription"), ToolboxBitmap(typeof(SuspendActivity), "Resources.Suspend.png"), ActivityValidator(typeof(SuspendValidator)), SRCategory("Standard"), ToolboxItem(typeof(ActivityToolboxItem))]
    public sealed class SuspendActivity : Activity
    {
        public static readonly DependencyProperty ErrorProperty = DependencyProperty.Register("Error", typeof(string), typeof(SuspendActivity));

        public SuspendActivity()
        {
        }

        public SuspendActivity(string name) : base(name)
        {
        }

        protected internal sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            executionContext.CloseActivity();
            string error = this.Error;
            executionContext.SuspendWorkflowInstance(error);
            return ActivityExecutionStatus.Closed;
        }

        protected internal override void Initialize(IServiceProvider provider)
        {
            if (base.Parent == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_MustHaveParent"));
            }
            base.Initialize(provider);
        }

        [MergableProperty(false), SRDescription("SuspendErrorMessageDescr"), DefaultValue((string) null), Browsable(true), SRCategory("Activity")]
        public string Error
        {
            get
            {
                return (base.GetValue(ErrorProperty) as string);
            }
            set
            {
                base.SetValue(ErrorProperty, value);
            }
        }
    }
}

